<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            width: 1000px;
            height: 50px;
            border: 1px solid #000;
            margin: 50px auto;
            overflow: hidden;
        }
        
        .box ul {
            width: 5000px;
            position: relative;
            list-style: none;
        }
        
        .box ul li {
            width: 200px;
            height: 50px;
            float: left;
            line-height: 50px;
            text-align: center;
            color: #fff;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div id="box" class="box">
        <ul id="list">
            <li style="background-color: blanchedalmond">1</li>
            <li style="background-color: rgb(27, 25, 179)">2</li>
            <li style="background-color: rgb(34, 22, 5)">3</li>
            <li style="background-color: rgb(182, 15, 51)">4</li>
            <li style="background-color: rgb(76, 175, 46)">5</li>
        </ul>
    </div>
    <script>
        var box = document.getElementById("box");
        var list = document.getElementById("list");
        list.innerHTML += list.innerHTML;

        // 全局变量，表示当前list的left值
        var left = 0;
        var timer;
        //定时器
        move();

        function move() {
            clearInterval();
            timer = setInterval(function() {
                left -= 4;
                if (left <= -1000) {
                    left = 0;
                }
                list.style.left = left + "px";
            }, 20);
        }
        // 鼠标进入停止定时器
        box.onmouseenter = function() {
            clearInterval(timer);
        };
        box.onmouseleave = function() {
            move();
        };
    </script>
</body>

</html>